package com.yby.mall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.yby.common.utils.PageUtils;
import com.yby.mall.product.entity.ProductAttrValueEntity;
import com.yby.mall.product.vo.AttrVo;
import com.yby.mall.product.vo.ProductAttrValueVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yby.mall.product.entity.AttrEntity;
import com.yby.mall.product.service.AttrService;
import com.yby.common.utils.R;



/**
 * 商品属性
 *
 * @author yangbingying
 * @email 2771355658@qq.com
 * @date 2021-07-09 20:49:20
 */
@Api(value = "", tags = "商品属性")
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;

    /**
     * 列表
     */
    @GetMapping("/{type}/list/{catId}")
    public R list(@PathVariable Long catId,@PathVariable String type, Integer page,Integer limit,String key){
        return  attrService.queryPage(catId,type,page,limit,key);
    }

    @GetMapping("/base/listforspu/{spuId}")
    public R baseListforSpu(@PathVariable Long spuId){
        return attrService.baseListforSpu(spuId);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    public R info(@PathVariable("attrId") Long attrId){
	//	AttrEntity attr = attrService.getById(attrId);
        return attrService.info(attrId);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrVo attrVo){
        return attrService.saveAttr(attrVo);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody AttrVo attrVo){
        return attrService.modify(attrVo);
    }

    @PostMapping("/update/{spuId}")
    public R update(@RequestBody List<ProductAttrValueVo> list,@PathVariable Long spuId){
        return attrService.updateProductAttrVal(list,spuId);
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrIds){
        return attrService.deleteByIds(Arrays.asList(attrIds));
    }

}
